package com.chuck.geohash.queries;

import java.util.List;

import com.chuck.geohash.bean.BoundingBox;
import com.chuck.geohash.bean.GeoHash;
import com.chuck.geohash.bean.Point;
import com.chuck.geohash.bean.WGS84Point;
import com.chuck.geohash.util.DistanceUntil;
import com.chuck.geohash.util.GeoHashSizeTable;
import com.chuck.geohash.util.VincentyGeodesy;

public class CommonGeoHashCircleQuery implements GeoHashQuery {
	
	private static final long serialVersionUID = 1263295371663796291L;
	
	private double radius;
	
	private GeoHash geoHash ;
	
	private Point center;
	
	private int bite;
	
	private static  double EARTH_RADIUS = 6378.137;
	
	public CommonGeoHashCircleQuery() {
		super();
	}

	public CommonGeoHashCircleQuery(Point center,double radius) {
		super();
		this.center=center;
		this.radius = radius;
		this.bite = GeoHashSizeTable.numberOfBitsForOverlappingGeoHash(getDisLngByRadius());
		this.geoHash = GeoHash.withBitPrecision(center.getLatitude(), center.getLongitude(),bite );
		double maxLength = 2*radius*Math.sqrt(2);
		while(getDistance(this.geoHash.getBoundingBox())< maxLength){
			bite--;
			this.geoHash = GeoHash.withBitPrecision(center.getLatitude(), center.getLongitude(),bite );
		}
	}

	private double getDistance(BoundingBox boundingBox) {
		// TODO Auto-generated method stub
		return DistanceUntil.GetDistance(boundingBox.getMaxLat(), boundingBox.getMaxLon(), boundingBox.getMinLat(),boundingBox.getMinLon());
	}

	public boolean contains(GeoHash hash) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean contains(WGS84Point point) {
		// TODO Auto-generated method stub
		return false;
	}

	public List<GeoHash> getSearchHashes() {
		// TODO Auto-generated method stub
		return null;
	}

	public String getWktBox() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public double getDisLngByRadius(){
		return (radius/(Math.PI*2*EARTH_RADIUS))*360;
	}

	public String getBase32(){
		return geoHash.toBase32();
	}
}
